package com.heima.health.controller;

import com.heima.health.entity.Result;
import com.heima.health.service.OrderSettingService;
import com.heima.health.utils.poi.POIUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("ordersetting")
@Api(tags = "预约管理开发")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    @PostMapping("importOrderSettings")
    @ApiOperation(value = "预约数据批量导入",notes = "将excel中数据导入数据库")
    public Result importOrderSettings(@RequestParam("excelFile")MultipartFile file) throws IOException {
        //判断文件是否合法
        POIUtils.checkFile(file);
        List<String[]> readExcel = POIUtils.readExcel(file);
        return new Result(orderSettingService.importOrderSettings(readExcel));
    }

    @GetMapping("findSettingData/{year}/{month}")
    @ApiOperation(value = "查询本月预约",notes = "根据年和月查询本月预约讯息")
    public Result findSettingData(@PathVariable("year") int year ,@PathVariable("month")int month) throws IOException {
        return new Result(orderSettingService.findSettingData(year,month));
    }

    @PutMapping("updateNumberByOrderDate/{number}/{orderdate}")
    @ApiOperation(value = "更新预约数",notes = "根据日期更新最大预约数")
    public Result updateNumberByOrderDate(@PathVariable("number") int number ,@PathVariable("orderdate")String orderdate) throws IOException {
        return new Result(orderSettingService.updateNumberByOrderDate(number,orderdate));
    }
}
